<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            width: 1000px;
            display: flex;
            margin: auto;
            cursor: pointer;
        }

        li {
            background-color: aqua;
            color: red;
            padding: 10px 15px;
            border-radius: 20px;
        }

        li.action {
            background-color: red;
            color: aqua;
        }

        .box {
            position: relative;

        }

        .box>div {
            height: 300px;
            border: 1px solid #000;
            display: none;
            width: 1000px;
            margin: auto;
        }

        .box>div.action {
            display: block;
        }
    </style>
</head>

<body>
    <ul>
        <li class="action">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="box">
        <div class="action">《雪天》</div>
        <div>我们一起去尿尿。</div>
        <div>你，尿了一条坑。</div>
        <div>我，尿了一个线。</div>
    </div>
    <script>
        var lis = document.querySelectorAll('li');
        var divs = document.querySelector('.box').querySelectorAll('div');

        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('index', i);
            lis[i].onclick = function () {
                for (let j = 0; j < lis.length; j++) {
                    lis[j].className = '';

                }
                this.className = 'action';
                let index = this.getAttribute('index');
                // 清空所有的样式
                for (let j = 0; j < divs.length; j++) {
                    divs[j].style.display = 'none';
                }
                // 当前样式改变
                divs[index].style.display = 'block';
            }

        }

    </script>
</body>

</html>